/**
 * Created by Administrator on 2018/1/18.
 */
layui.use(['jquery','form','layer'], function(){
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form;

    //监听表单提交
    form.on('submit(submit_btn)', function(data){
        post_data = data.field;
        $.ajax({
            type: "POST",
            data: post_data,
            cache:false,
            url: "/user/update_info",
            dataType: "json",
            success: function(data){
                if(data.code == 200){
                    layer.msg(data.msg,{icon:1});
                    return false;
                }else if(data.code == 201){
                    layer.msg(data.msg,{icon:2});
                    return false;
                }else{
                    //返回错误信息
                    var message = '';
                    $.each(data.data, function(idx, obj) {
                        message += obj+"<br/>";
                    });

                    layer.open({
                        content: message,
                        skin: 'msg',
                        time: 3 //2秒后自动关闭
                    });
                    return false;
                }
            },
            error:function(data){
                return false;
            }
        });
    });

});
